package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


import androidx.appcompat.app.AppCompatActivity;

import com.example.androiduidemo.R;
import com.example.myapplication.javabean.User;

public class Sign extends AppCompatActivity {
    private MySQLiteOpenHelper1 mySQLiteOpenHelper;
    private EditText meduser,medpassword,mname,mid,mclassName;


    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Compiler EdgeToEdge = null;
        EdgeToEdge.enable();
        setContentView(R.layout.activity_sign);
        mySQLiteOpenHelper = new MySQLiteOpenHelper1(this);
        find();

    }
    public void find()
    {
        meduser=findViewById(R.id.ed_username_sign);
        medpassword=findViewById(R.id.ed_password_sign);
        mname=findViewById(R.id.student_id);
        mid=findViewById(R.id.student_id);
        mclassName=findViewById(R.id.student_class);
    }

    public void return_login(View view)
    {
        Intent intent1 = new Intent(Sign.this, Login.class);
        startActivity(intent1);
    }
    public void insert(View view)
    {
        String s1 = meduser.getText().toString();
        String s2 = medpassword.getText().toString();//获取输入框里的值
        String s3 = mname.getText().toString();
        String s4 = mclassName.getText().toString();
        User user = new User(s1,s2,s3,s4);//传入实体类
        long register = mySQLiteOpenHelper.register(user);//传入数据库返回一个bool值
        if (register!=-1 )
        {
            Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(Sign.this, Login.class);
            startActivity(intent);
        }

        else
        {
            Toast.makeText(this, "注册失败，用户名被占用", Toast.LENGTH_SHORT).show();
        }


    }

}